#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) arr[i] = i + 1;
  do {
    for (int i = 0; i < n; i ++) {
      cout.width(5);
      cout << arr[i];
    }
    cout << endl;
  } while (next_permutation(arr.begin(), arr.end()));
}